import axios from 'axios'
// import { RES_URL } from './Url'

let elmsg = null
export const requst = (options) => {
  return new Promise(reslove => {
    const insta = axios.create({
           // baseURL: 'https://www.liulongbin.top:8888/api/private/v1/'
      baseURL: 'http://shiyansong.cn:8888/api/private/v1'
    })
    // 请求拦截
    insta.interceptors.request.use(config => {
      config.headers.Authorization = sessionStorage.getItem('token')
      return config
    })

    // 响应拦截
    insta.interceptors.response.use(res => {
      if (elmsg) elmsg.close()
      if (res.status != 200) return elmsg = ElMessage.error(res.data.meta.msg);
      elmsg = ElMessage({
      message: res.data.meta.msg,
      type: "success",
      });    
      // 打开有提示 成功失败的消息提示
      return res.data
    })

    insta(options).then(res => {
      reslove(res)
    })
  })
}